#!/usr/bin/env python
# coding=utf-8
# 框架顶部

import wsgiref.handlers
from google.appengine.ext import webapp
from google.appengine.api import users
from google.appengine.ext.webapp import util
import common

class TopHandler(webapp.RequestHandler):
	def get(self):
		user = users.get_current_user()
		if user:
			if users.is_current_user_admin():
				common.writeHtml(self, self.getHeader(),self.getBody(), "")
			else:
				common.writeNoPermissionMessage(self)
		else:
			self.redirect(users.create_login_url(self.request.uri))

	def getHeader(self):
		return '<link href="css/style.css" type="text/css" rel="stylesheet" /><link href="css/top.css" type="text/css" rel="stylesheet" />'

	def getBody(self):
		return """<div id="menu-div" style="position:absolute;z-index:999;width:100%;“>
	<ul>
		<li class="fix-spacel"></li>
		<li class="fix-spacer"></li>
		<li class="fix-spacel"></li>
		<li><a href="main" target="main-frame">Main Page</a></li>
		<li class="fix-spacer"></li>
	</ul>
	<br class="clear" />
</div>
<div id="load-div" style="padding: 3px; position:absolute;z-index:9999;
text-align: center;vertical-align: middle; 
color: #FFFFFF;width:100%; height:25px;
display: none;">
	<img src="images/loader.gif" width="16" height="16" alt="Loading..." style="vertical-align: middle" />&nbsp;&nbsp;Loading...
</div>"""

def main():
	application = webapp.WSGIApplication([('/top', TopHandler)],
		debug=True)
	util.run_wsgi_app(application)


if __name__ == '__main__':
	main()
